package com.sprites;

import java.util.ArrayList;

import com.bricks2break.AbstractBrickFactory;
import com.bricks2break.Statics;

public class BrickGroup {
	private ArrayList<Brick> bricks;
	private ArrayList<Brick> removeList;

	/**
	 * Brick group class constructor
	 * 
	 * @param lvlNumber
	 *            the number of the level
	 */
	public BrickGroup(int lvlNumber) {
		removeList = new ArrayList<Brick>();
		bricks = AbstractBrickFactory.makeBricks(lvlNumber);
	}

	/**
	 * Method that removes a brick
	 * 
	 * @param b
	 *            the brick to be removed
	 */
	public void removeBrick(Brick b) {
		removeList.add(b);
	}

	/**
	 * Draw method
	 * 
	 * @param canvas
	 */
	public void draw(android.graphics.Canvas canvas) {
		for (Brick b : bricks) {
			b.draw(canvas);
		}
		for (Brick b : removeList) {
			Statics.level.getCollisionLayer().removeSprite(b);
			bricks.remove(b);
			if(emptyBricks()){
				Statics.level.gameOver();
			}
		}
		removeList.clear();
	}

	/**
	 * Update method
	 * 
	 * @param dt
	 */
	public void update(float dt) {
		for (Brick b : bricks) {
			b.update(dt);
		}
	}

	/**
	 * Method that checks if there are no bricks left
	 * 
	 * @return
	 */
	public boolean emptyBricks() {
		if (bricks.isEmpty()) {
			return true;
		} else {
			return false;
		}
	}
}
